﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsApplication1
{
    public partial class F_YPZDWH : Form
    {
        public F_YPZDWH()
        {
            InitializeComponent();
        }

        SqlConnection conn;
        SqlCommand com;
        SqlDataReader dr;
        public static string s1;

        private void F_YPZDWH_Load(object sender, EventArgs e)
        {
            hyqk_comboBox.Items.Add("充足");
            hyqk_comboBox.Items.Add("短缺");
            hyqk_comboBox.Items.Add("奇缺");
            dlfl_comboBox.Items.Add("麻醉药");
            dlfl_comboBox.Items.Add("毒性药");
            dlfl_comboBox.Items.Add("精神Ⅰ类");
            dlfl_comboBox.Items.Add("精神Ⅱ类");
            dlfl_comboBox.Items.Add("普通药");
            czfl_comboBox.Items.Add("中药");
            czfl_comboBox.Items.Add("西药");
            czfl_comboBox.Items.Add("中成药");
            jzfl_comboBox.Items.Add("普价");
            jzfl_comboBox.Items.Add("贵重");
            jzfl_comboBox.Items.Add("昂贵");
            jxfl_comboBox.Items.Add("片剂");
            jxfl_comboBox.Items.Add("口服");
            jxfl_comboBox.Items.Add("注射");
            jxfl_comboBox.Items.Add("滴定");
            s1 = "0";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            conn = new SqlConnection();
            conn.ConnectionString = SQL.getCon;
            conn.Open();
            com = new SqlCommand();
            int i = 0;
            string s;
            com.CommandText = "select max(ypid) as id from yptx";
            com.Connection = conn;
            dr = com.ExecuteReader();
            dr.Read();
            s = dr["id"].ToString();
            //if (dr["id"].ToString() == null) i = i+1;
            i = int.Parse(s) + 1;
            //if (i = null) { i = 1; }
            //else i=i+1;
            conn.Close();
            conn.Open();
            com.CommandText = "insert into yptx(ypid,ypjx,dlfl,hyqk,jzfl,jjyf,sfps,yplx,kss,bm,mc,jldw) values(@ypid,@ypjx,@dlfl,@hyqk,@jzfl,@jjyf,@sfps,@yplx,@kss,@bm,@mc,@jldw)";
            SqlParameter ypid = new SqlParameter("ypid", SqlDbType.Int, 10);
            ypid.Value = i;
            com.Parameters.Add(ypid);
            SqlParameter ypjx = new SqlParameter("ypjx", SqlDbType.NVarChar , 20);
            ypjx.Value = jxfl_comboBox.Text;
            com.Parameters.Add(ypjx);
            SqlParameter dlfl = new SqlParameter("dlfl", SqlDbType.NVarChar , 20);
            dlfl.Value = dlfl_comboBox.Text;
            com.Parameters.Add(dlfl);
            SqlParameter hyqk = new SqlParameter("hyqk", SqlDbType.NVarChar , 20);
            hyqk.Value = hyqk_comboBox.Text;
            com.Parameters.Add(hyqk);
            SqlParameter jzfl = new SqlParameter("jzfl", SqlDbType.NVarChar , 20);
            jzfl.Value = jzfl_comboBox.Text;
            com.Parameters.Add(jzfl);
            SqlParameter jjsf = new SqlParameter("jjyf", SqlDbType.NVarChar , 20);
            if (checkBox1.Checked)
                jjsf.Value = "是";
            else jjsf.Value = "否";
            com.Parameters.Add(jjsf);
            SqlParameter sfps = new SqlParameter("sfps", SqlDbType.NVarChar , 20);
            if (checkBox3.Checked)
                sfps.Value = "是";
            else sfps.Value = "否";
            com.Parameters.Add(sfps);
            SqlParameter yplx = new SqlParameter("yplx", SqlDbType.NVarChar , 20);
            yplx.Value = czfl_comboBox.Text;
            com.Parameters.Add(yplx);
            SqlParameter kss = new SqlParameter("kss", SqlDbType.NVarChar , 20);
            if (checkBox2.Checked)
                kss.Value = "是";
            else kss.Value = "否";
            com.Parameters.Add(kss);
            SqlParameter ypbm = new SqlParameter("bm", SqlDbType.NVarChar , 20);
            ypbm.Value = textBox1.Text;
            com.Parameters.Add(ypbm);
            SqlParameter ypmc = new SqlParameter("mc", SqlDbType.NVarChar , 20);
            ypmc.Value = textBox2.Text;
            com.Parameters.Add(ypmc);
            SqlParameter jldw = new SqlParameter("jldw", SqlDbType.NVarChar , 20);
            jldw.Value = textBox4.Text;
            com.Parameters.Add(jldw);
            com.ExecuteNonQuery();
            conn.Close();
            s1 = "1";
            F_YPCX.s1 = i.ToString();
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}